package com.ruoyi.web.controller.basicData.ruleSetting;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.basicData.ruleSetting.domain.DocumentRules;
import com.ruoyi.basicData.ruleSetting.service.IDocumentRulesService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单据规则Controller
 * 
 * @author ruoyi
 * @date 2024-01-23
 */
@RestController
@RequestMapping("/basicData/ruleSetting/docConfig")
public class DocumentRulesController extends BaseController
{
    @Autowired
    private IDocumentRulesService documentRulesService;

    /**
     * 查询单据规则列表
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:docConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(DocumentRules documentRules)
    {
        startPage();
        List<DocumentRules> list = documentRulesService.selectDocumentRulesList(documentRules);
        return getDataTable(list);
    }

    /**
     * 导出单据规则列表
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:docConfig:export')")
    @Log(title = "单据规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DocumentRules documentRules)
    {
        List<DocumentRules> list = documentRulesService.selectDocumentRulesList(documentRules);
        ExcelUtil<DocumentRules> util = new ExcelUtil<DocumentRules>(DocumentRules.class);
        util.exportExcel(response, list, "单据规则数据");
    }

    /**
     * 获取单据规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:docConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(documentRulesService.selectDocumentRulesById(id));
    }

    /**
     * 新增单据规则
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:docConfig:add')")
    @Log(title = "单据规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocumentRules documentRules)
    {
        documentRules.setCreateBy(getUsername());
        return toAjax(documentRulesService.insertDocumentRules(documentRules));
    }

    /**
     * 修改单据规则
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:docConfig:edit')")
    @Log(title = "单据规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocumentRules documentRules)
    {
        documentRules.setUpdateBy(getUsername());
        return toAjax(documentRulesService.updateDocumentRules(documentRules));
    }

    /**
     * 删除单据规则
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:docConfig:remove')")
    @Log(title = "单据规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(documentRulesService.deleteDocumentRulesByIds(ids));
    }
}
